<template>
  <div class="page-department">
    <div class="component-mainHeader">
      <div class="top">
        <div class="topleft">
          <p>
            <span class="iconfont" style="color:#1abc9a;margin-right:3px;">&#xe607;</span>建项审批列表
          </p>
        </div>
        <div class="topright">
          <el-button type="info" @click="$router.go(0)">
            <span style="font-weight:700;margin-right:5px;" class="iconfont">&#xe662;</span>刷新
          </el-button>
        </div>
      </div>
    </div>
    <div class="component-searchHeader">
      <div class="search-header">
        <div class="left-title">
          <p class="left-text">
            <span class="iconfont">&#xe63d;</span> 筛选查询
          </p>
          <div class="right">
            <button @click="searchInfo()">查询</button>
          </div>
        </div>
      </div>
    </div>
    <div class="component-search-box">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="输入搜索：" style="margin-bottom:0">
          <el-input
            v-model="formInline.search"
            clearable
            placeholder="项目编号/内部编号"
            style="width:217px;"
          ></el-input>
        </el-form-item>
        <el-form-item style="margin-bottom:0">
          <span class="demonstration">开始日期：</span>
          <el-date-picker
            v-model="formInline.date"
            type="date"
            placeholder="选择日期"
            format="yyyy 年 MM 月 dd 日"
            value-format="timestamp"
            default-time="00:00:00"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="进度：" style="margin-bottom:0">
          <el-select v-model="formInline.step" placeholder="请选择进度" clearable>
            <el-option
              v-for="item in selectPro"
              :key="item.constCode"
              :label="item.const_name"
              :value="item.const_code"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="类别：" style="margin-left: 25px;">
          <el-select v-model="formInline.progress" placeholder="请选择类别" clearable>
            <el-option
              v-for="item in selectMajor"
              :key="item.constCode"
              :label="item.const_name"
              :value="item.const_code"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <div class="component-listHeader">
      <div class="search-header">
        <div class="left-title">
          <p class="left-text">
            <span class="iconfont">&#xe61e;</span>
            {{title}}
          </p>
        </div>
      </div>
    </div>
    <!-- 表格 -->
    <div class="table">
      <el-table ref="multipleTable" :data="info" tooltip-effect="dark" style border>
        <el-table-column label="项目编号" align="center" width="100" prop="proNo"></el-table-column>
        <el-table-column label="项目内部编号" align="center" width="100" prop="innerNo"></el-table-column>
        <el-table-column label="开始时间" align="center" width="90">
          <template slot-scope="scope">{{scope.row.sworkDate | timeFilter}}</template>
        </el-table-column>
        <el-table-column label="项目名称" align="center" width="100" prop="proName"></el-table-column>
        <el-table-column label="年度" align="center" width="100" prop="proYear"></el-table-column>
        <el-table-column label="甲方" align="center" width="100" prop="owner"></el-table-column>
        <el-table-column label="项目地址" align="center" width="100" prop="proAddr"></el-table-column>
        <el-table-column label="类别" align="center" width="100" prop="proMajor"></el-table-column>
        <el-table-column label="进度" align="center" prop="flowStep"></el-table-column>
        <el-table-column label="审核状态" align="center" prop="code">
          <template slot-scope="scope">
            <!-- <div>{{scope.row.code}}</div> -->
            <div>
              <el-button
                @click="records(scope.row.proId)"
                type="text"
                size="small"
                class="red"
                style="color:#1abc9a;"
              >审核记录</el-button>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <div>
              <el-button
              @click="$router.push({name:'approveDetail',params:{proId:scope.row.proId}})"
              type="text"
              size="small"
              class="red"
              style="color:#1abc9a;"
            >查看详情</el-button>
            </div>
            <div>
              <el-button
              type="text"
              size="small"
              class="red"
              style="color:#1abc9a;"
              v-show="scope.row.flowStep=='项目部立项' && ms_RoleName == 'ProjectClerk'"
              @click="$router.push({name:'buildPro',params:{proId:scope.row.proId, belongOrg:scope.row.belongOrg}})"
            >编辑</el-button>
            </div>
            <div>
              <el-button
              type="text"
              size="small"
              class="red"
              style="color:#1abc9a;"
              v-show="scope.row.flowStep=='项目部立项' &&ms_RoleName == 'ProjectClerk'"
              @click="commitInfo(scope.row.proId)"
            >提交审核</el-button>
            </div>
            <div>
              <el-button
              type="text"
              size="small"
              class="red"
              v-show="scope.row.flowStep=='项目部立项' &&ms_RoleName == 'ProjectClerk'"
              style="color:#1abc9a;"
              @click="delInfo(scope.row.proId,scope.row.flowStep)"
            >删除</el-button>
            </div>
            <div>
              <el-button
              @click="handleIdea(scope.row.proId,scope.row.code.nextTG,scope.row.code.nextBH)"
              v-show="scope.row.flowStep == '项目部文员审核通过' &&ms_RoleName == 'ProjectManager'"
              type="text"
              size="small"
              class="red"
              style="color:#1abc9a;"
            >审批意见</el-button>
            <el-button
              v-show="scope.row.flowStep == '项目部经理初审通过' &&ms_RoleName == 'CenterClerk'"
              @click="handleIdea(scope.row.proId,scope.row.code.nextTG,scope.row.code.nextBH)"
              type="text"
              size="small"
              class="red"
              style="color:#1abc9a;"
            >审批意见</el-button>
            <el-button
              v-show="scope.row.flowStep == '管理部文员通过' &&ms_RoleName == 'CenterDeputy'"
              @click="handleIdea(scope.row.proId,scope.row.code.nextTG,scope.row.code.nextBH)"
              type="text"
              size="small"
              class="red"
              style="color:#1abc9a;"
            >审批意见</el-button>
            <el-button
              v-show="scope.row.flowStep == '管理部副总通过' &&ms_RoleName == 'CenterBOSS'"
              @click="handleIdea(scope.row.proId,scope.row.code.nextTG,scope.row.code.nextBH)"
              type="text"
              size="small"
              class="red"
              style="color:#1abc9a;"
            >审批意见</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 分页 -->
    <div class="component-paging" v-show="info.length>0">
      <div class="table-bottom">
        <div class="bottom-left"></div>
        <div class="paging">
          <div class="paging-left">
            <p>
              共
              <span>{{Math.ceil(total/pageSize)}}</span> 页/
              <span>{{total}}</span> 条数据
            </p>
          </div>
          <el-pagination
            background
            @size-change="SizeChange($event,dataInit,currentPage,pageSize)"
            @current-change="CurrentChange($event,dataInit,currentPage,pageSize)"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30]"
            :page-size="pageSize"
            layout="sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </div>
    </div>
    <!--审核记录详情 弹框-->
    <div class="component-model">
      <el-dialog title="查看详情" :visible.sync="dialogVisible" width="600px">
        <el-table ref="multipleTable" :data="infoDetail" tooltip-effect="dark" style border>
          <el-table-column label="审核时间" align="center" width="140">
            <template slot-scope="scope">{{scope.row.lastCheckdate | timeFilter}}</template>
          </el-table-column>
          <el-table-column label="审核人员" align="center" width="105" prop="userName"></el-table-column>
          <el-table-column label="审核结果" align="center" width="150" prop="progressName">
            
          </el-table-column>
          <el-table-column label="反馈详情" align="center" prop="lastCheckremark"></el-table-column>
        </el-table>
      </el-dialog>
    </div>
    <!-- 审批意见 -->
    <div class="component-model">
      <el-dialog title="审核意见" :visible.sync="ideaModel.show" width="600px">
        <div class="hadRadio">
          <el-form
            ref="form"
            :model="ideaModel"
            label-width="100px"
            style="width:300px;margin:0 auto;"
          >
            <el-form-item label="审核意见：">
              <el-radio-group v-model="ideaModel.idea" style="margin-left:-30px;">
                <el-radio label="true">同意</el-radio>
                <el-radio label="false">驳回</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="备注：" style="width:300px;">
              <el-input type="textarea" v-model="ideaModel.remark" style="margin-left:20px;"></el-input>
            </el-form-item>
          </el-form>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="ideaModel.show = false">取消</el-button>
          <el-button @click="ideaCommit">确定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { timingSafeEqual } from 'crypto';
export default {
  name: "approveList",
  data() {
    return {
      ms_RoleName:localStorage.getItem('roleName'),
      title: "建项列表",
      info: [],
      infoDetail: [],
      formInline: {
        search: "",
        date: "",
        progress: "",
        step: ""
      },
      limit: true,
      // 数据总条数
      total: 0,
      // 每页显示数据的条数
      pageSize: 10,
      // 当前显示的页面页码
      currentPage: 1,
      dialogVisible: false, //弹框是否显示
      selectMajor: [],
      selectPro: [],
      //审核意见弹窗的值
      ideaModel: {
        show: false,
        proId: "",
        remark: "",
        idea: ""
      }
    };
  },
  created() {
    this.progressInit();
    this.majorInit();
    this.dataInit();
  },
  mounted() {},
  methods: {
    // 进度下拉框选项初始化
    progressInit() {
      let that = this,
        suCb = res => {
          console.log(res);
          that.selectPro = that.deepClone(res.data.data);
        },
        erCb = res => {
          console.log(res);
        },
        req = {
          url: "/api/web/proProject/selectConst",
          methods: "post",
          data: { object: "ProCheckProgress" },
          success: suCb,
          error: erCb
        };
      that.$https(req);
    },
    // 类别下拉框选项初始化
    majorInit() {
      let that = this,
        suCb = res => {
          console.log(res);
          that.selectMajor = that.deepClone(res.data.data);
        },
        erCb = res => {
          console.log(res);
        },
        req = {
          url: "/api/web/proProject/selectConst",
          methods: "post",
          data: { object: "proMajor" },
          success: suCb,
          error: erCb
        };
      that.$https(req);
    },
    // 查询按钮
    searchInfo() {
      this.currentPage = 1;
      this.dataInit();
    },
    // 表格数据初始化
    dataInit() {
      let that = this,
        suCb = res => {
          console.log("查询结果", res);
          that.info = res.data.data.list;
          that.total = res.data.data.total;
        },
        erCb = res => {
          console.log(res);
        },
        params = {
          url: ""
        },
        req = {
          url: "/api/web/proProject/selectProProjectList",
          methods: "post",
          data: {
            proNo: that.formInline.search,
            proMajor: that.formInline.progress,
            pn: that.currentPage + "",
            psize: that.pageSize + "",
            flowStep: that.formInline.step,
            sworkDate:
              that.formInline.date === null ? "" : that.formInline.date + "",
            roleName:localStorage.getItem("roleName")
          },
          success: suCb,
          error: erCb
        };
      console.log("查询参数", req.data);
      that.$https(req);
    },
    //审核记录
    records(id) {
      this.dialogVisible = true;
      let that = this,
        suCb = res => {
          console.log("审核记录结果", res);
          if (res.data.data.length > 0) {
            that.infoDetail = res.data.data;
          } else {
            that.infoDetail = [];
          }
        },
        erCb = res => {
          console.log(res);
        },
        params = {
          url: ""
        },
        req = {
          url: "/api/web/proCheckflow/SelectChectListByProId",
          methods: "post",
          data: { proId: id },
          success: suCb,
          error: erCb
        };
      console.log("审核记录参数", req.data);
      that.$https(req);
    },
    // 删除按钮
    delInfo(id,flowStep) {
      this.$confirm("确认删除吗？")
        .then(_ => {
          let that = this,
            suCb = res => {
              that.$msg("删除成功！");
              that.dataInit();
            },
            erCb = res => {
              console.log(res);
            },
            req = {
              url: "/api/web/proProject/deleteByProId",
              methods: "post",
              data: {
                proId: id,
                msg:flowStep
              },
              success: suCb,
              error: erCb
            };
          that.$https(req);
        })
        .catch(_ => {});
    },
    // 提交审核
    commitInfo(id) {
      console.log(id)
      let that = this,
        suCb = res => {
          console.log("文员提交审核结果：", res);
          if(res.data.flag == 1){
            that.$msg('提交成功！')
            that.dataInit();
          }
        },
        erCb = res => {
          console.log(res);
          that.$msg('提交失败,网络异常！')
        },
        req = {
          url: "/api/web/proProject/updateProCheck",
          methods: "post",
          data: {
            proId: id
          },
          success: suCb,
          error: erCb
        };
      that.$https(req);
    },
    // 审批意见
    handleIdea(id,tg,bh) {
      this.ideaModel.show = true;
      this.ideaModel.proId = id;
      this.ideaModel.tg = tg;
      this.ideaModel.bh = bh;
    },
    // 审批意见提交
    ideaCommit() {
      let num = this.ideaModel.idea == "true" ? this.ideaModel.tg:this.ideaModel.bh,that = this,
        suCb = res => {
          console.log('审批意见结果',res);
          if(res.data.flag == 1){
            that.$msg('提交成功！');
            that.ideaModel.show = false;
            that.dataInit();
          }
        },
        erCb = res => {
          that.$msg('提交失败，权限受限！')
        },
        req = {
          url: "/api/web/proProject/checkedProJect",
          methods: "post",
          data: {
            proId: that.ideaModel.proId,
            number: num,
            errorDesc: that.ideaModel.remark,
            updateUser:localStorage.getItem("ms_userId")
          },
          success: suCb,
          error: erCb
        };
      console.log(req.data);
      if(req.data.errorDesc == ""&& that.ideaModel.idea == "false"){
        that.$msg('提交失败，驳回必须填写备注！')
      }else if(req.data.number == 0){
        that.$msg('提交失败，您的角色没有权利提交！')
      }else{
        that.$https(req);
      }
    }
  }
};
</script>

<style scoped>
.component-searchHeader .search-header {
  width: 1100px;
  box-sizing: border-box;
  border: 1px solid rgba(228, 228, 228, 1);
  background-color: rgba(255, 255, 255, 1);
  margin: 20px auto 0;
}

.component-searchHeader .search-header .left-title {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background-color: rgba(243, 243, 243, 1);
  height: 45px;
  box-sizing: border-box;
}

.component-searchHeader .search-header .left-title .left-text {
  width: 20%;
  color: #666;
  line-height: 45px;
  font-family: "微软雅黑";
  font-weight: 400;
  font-size: 12px;
  text-align: left;
  margin: 0 0 0 30px;
}

.component-searchHeader .right {
  width: 70%;
  display: flex;
  justify-content: flex-end;
  margin-right: 30px;
}

.component-searchHeader .right button {
  padding: 0 15px;
  height: 30px;
  margin: 6px 5px;
  line-height: 30px;
  font-size: 12px;
  color: #666;
  background-color: #fff;
  border: 1px solid #ccc;
}

.component-searchHeader .right button:hover {
  background-color: #f3f3f3;
}

.component-search-box {
  width: 1100px;

  box-sizing: border-box;
  background-color: #fff;
  border: 1px solid #e4e4e4;
  border-top: none;
  margin: 0 auto;
  text-align: left;
  padding-left: 30px;
  line-height: 60px;
}

.component-search-box .el-input__inner {
  height: 35px;
  display: inline-block;
}

.component-listHeader .search-header {
  width: 1100px;
  box-sizing: border-box;
  border: 1px solid rgba(228, 228, 228, 1);
  background-color: rgba(255, 255, 255, 1);
  margin: 20px auto 0;
  border-bottom: 0;
}

.component-listHeader .search-header .left-title {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background-color: rgba(243, 243, 243, 1);
  height: 45px;
  box-sizing: border-box;
}

.component-listHeader .search-header .left-title .left-text {
  width: 20%;
  color: #666;
  line-height: 45px;
  font-family: "微软雅黑";
  font-weight: 400;
  font-size: 12px;
  text-align: left;
  margin: 0 0 0 30px;
}

.component-listHeader .search-header .right {
  width: 70%;
  display: flex;
  justify-content: flex-end;
  margin-right: 10px;
}

.component-listHeader .search-header .right button {
  padding: 0 15px;
  height: 30px;
  width: 80px;
  margin: 6px 5px;
  line-height: 30px;
  font-size: 14px;
  color: #666;
  background-color: #fff;
  border: 1px solid #ccc;
}

.component-listHeader .search-header .right button:hover {
  background-color: #f3f3f3;
}

.right button:hover {
  cursor: pointer;
}
.component-listHeader .search-header .right .right-select-margin {
  margin-top: 6px;
  margin-right: 8px;
}

.component-table-header {
  width: 1100px;
  margin: 0 auto;
  display: flex;
  border: 1px solid #e4e4e4;
  background-color: #f9fafc;
  height: 45px;
  line-height: 45px;
  padding: 0;
  list-style: none;
  justify-content: space-between;
  box-sizing: border-box;
  border-top: none;
}

/* 下面都是修改饿了么ui的下拉框和按钮选中后的样式 */

.el-select .el-input.is-focus .el-input__inner,
.el-select .el-input__inner:focus {
  border-color: #e4e4e4;
}

.el-select-dropdown__item.selected {
  color: #666;
  font-weight: 400;
}

.el-select-dropdown {
  min-width: 100px !important;
  top: 50px !important;
  margin-left: 5px;
}
.el-select-dropdown__item {
  height: 26px;
  line-height: 26px;
}

.el-select .el-input__inner {
  width: 100px;
  padding: 0 8px;
  /* height: 30px; */
  margin: 6px 5px;
}

.table {
  width: 1100px;
  margin: 0 auto;
}

.el-table .cell a {
  color: #1abc9a;
  text-decoration: none;
  cursor: pointer;
}
</style>
